#include "AvailableTalents.h"
#include "Player.h"
#include "Game.h"
#include "ObjectDatabase.h"


AvailableTalents::AvailableTalents(Player* player) {
	m_talents = new std::vector<Talent>();
	for(int i = 0; i < NUM_TALENTS; i++) {
		if(!player->hasTalent(Talent(i))) {
			const TalentInfo talent = g_objectDatabase->getTalentInfo(Talent(i));
			if(talent.gender == 4 || (talent.gender == 3 && player->getGenderType() != GT_NONE) || player->getGenderType() == talent.gender) {
				bool hasStats = true;
				bool hasTalents = true;
				for(int j = 0; j < NUM_STATS; j++) {
					if(player->getStat(Stat(j)) < talent.stats[j])
						hasStats = false;
				}
				for(std::set<Talent>::iterator iter = talent.prereqs.begin(); iter != talent.prereqs.end(); iter++) {
					if(!player->hasTalent(*iter))
						hasTalents = false;
				}
				if(hasStats && hasTalents)
					m_talents->push_back(Talent(i));
			}
		}
	}
}

AvailableTalents::~AvailableTalents() {
	m_talents->clear();
	delete m_talents;
}

int AvailableTalents::getTalent(int mod) const {
	if(mod >= 0 && mod < int(m_talents->size()))
		return m_talents->at(mod);
	else
		return -1;
}
